package com.framework.loippi.controller.swaggerapi;

import com.framework.loippi.api.utils.ApiUtils;
import com.framework.loippi.controller.swaggerapi.vo.UserInfo;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 接口样列，非正式接口
 * 所有接口必须以 .json后缀，不能省略
 * 相关注解使用说明：
 * https://segmentfault.com/a/1190000010465989
 *
 * @author wcj
 */
@Controller
@RequestMapping(value = "/api/swagger")
@Api(value = "接口样列，非正式接口", description = "接口样列，非正式接口", tags = {"接口样列，非正式接口"})
public class SwaggerAPIController {

    @ApiOperationSupport(
        responses = @DynamicResponseParameters(
            properties = {
                    @DynamicParameter(name = "images", value = "用户token", dataTypeClass = String.class)
            }
        )
    )
    @RequestMapping(value = "/queryUserById.json", method = RequestMethod.POST)
    @ApiOperation(value = "根据用户id查询用户信息", response = UserInfo.class, notes = "接口的notes说明：需要user的id", httpMethod = "POST", produces = "application/json")
    @ApiResponses({@ApiResponse(code = 1, message = "操作成功"), @ApiResponse(code = 0, message = "操作失败")})//错误响应
    public @ResponseBody
    String queryUserById(
            @ApiParam(name = "userId", required = true, value = "用户Id") @RequestParam("userId") int userId,
            //UserInfo userInfo,
            HttpServletRequest request) {
        UserInfo result = new UserInfo();
        result.setUserName("八福堂后台");
        return ApiUtils.success(result);
    }


    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(value = "更新用户信息", response = UserInfo.class, notes = "接口的notes说明：需要user的id", httpMethod = "POST", produces = "application/json")
    @ApiResponses({@ApiResponse(code = 1, message = "操作成功"), @ApiResponse(code = 0, message = "操作失败")})//错误响应
    public @ResponseBody
    String update(
            UserInfo userInfo,
            HttpServletRequest request) {
        UserInfo result = new UserInfo();
        result.setUserName("八福堂后台");
        return ApiUtils.success(result);
    }

}
